package com.huadao.cart_ccs.experiment.log.paramsAnysis;

import android.os.Bundle;

import com.github.mikephil.charting.data.Entry;
import com.huadao.cart_ccs.R;
import com.huadao.cart_ccs.common.ParamsPreferences;
import com.huadao.cart_ccs.common.UtilHelpers;
import com.huadao.cart_ccs.common.deviceController.O2Controller;
import com.huadao.cart_ccs.greendao.GreenDaoManager;
import com.huadao.cart_ccs.greendao.entity.O2;
import com.huadao.cart_ccs.greendao.gen.O2Dao;

import java.util.List;

public class O2Frag extends BaseEnvironmentFrag {

    private O2Dao o2Dao;

    public static O2Frag getInstance(int day) {
        Bundle bundle = new Bundle();
        bundle.putInt("day", day);
        O2Frag o2Frag = new O2Frag();
        o2Frag.setArguments(bundle);
        return o2Frag;
    }
    @Override
    protected void initView() {
        o2Dao = GreenDaoManager.getInstance().getNoCacheSession().getO2Dao();
    }

    @Override
    protected float getLimitValue() {
        return (float) O2Controller.getInstance().getSettedValue().floatValue();
    }

    @Override
    protected int getLimitLineColor() {
        return getResources().getColor(R.color.limit_line);
    }

    @Override
    protected String getLabel() {
        return getString(R.string.O2);
    }

    @Override
    protected void setDataSet() {
        List<O2> o2List = o2Dao.queryBuilder().where(O2Dao.Properties.ProjectId.eq(projectId), O2Dao.Properties.StageId.eq(stageId)).orderDesc(O2Dao.Properties.Date).limit(8640).list();
        for (int i = o2List.size()-1; i >-1; i--) {
            O2 o2 = o2List.get(i);
            float x = UtilHelpers.getTime(o2.getDate());
            Entry entry = new Entry(x, (float) o2.getO2());
            lineData.addEntry(entry,0);
        }
    }

    @Override
    protected int getLineColor() {
        return getResources().getColor(R.color.O2_line);
    }
}
